package cn.simple.manager.configuration;

import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;


@EnableJpaRepositories(basePackages = "cn.simple.manager.Repository")
@EntityScan("cn.simple.manager.todo")
@Configuration
public class DBConfiguration {
    @Bean  
    PlatformTransactionManager transactionManager() {
        return new JpaTransactionManager();
    }

    @Bean
    public JpaVendorAdapter jpaVendorAdapter() {
        HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter();
        hibernateJpaVendorAdapter.setGenerateDdl(true);
        hibernateJpaVendorAdapter.setShowSql(true);
        hibernateJpaVendorAdapter.setDatabasePlatform("org.hibernate.dialect.SQLiteDialect");
        return hibernateJpaVendorAdapter;
    }

//    @Bean
//    LocalContainerEntityManagerFactoryBean customerEntityManagerFactory(DynamicDataSource dynamicDataSource) {
//
//        HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
//        jpaVendorAdapter.setGenerateDdl(true);
//
//        LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
//
//        factoryBean.setDataSource(dynamicDataSource);
//        factoryBean.setJpaVendorAdapter(jpaVendorAdapter);
////        factoryBean.setPackagesToScan(CustomerConfig.class.getPackage().getName());
//        return factoryBean;
//    }

}
